package com.example.drive.coach.controller;


import com.example.drive.coach.pojo.dto.CoachDTO;
import com.example.drive.coach.pojo.entity.Coach;
import com.example.drive.coach.pojo.vo.CoachWage;
import com.example.drive.coach.service.CoachService;
import com.example.drive.common.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 教练控制层
 */
@RestController
@RequestMapping("coach")
public class CoachController {
    @Autowired
    private CoachService coachService;

    /**
     * 获取教练列表
     * @return
     */
    @GetMapping("list")
    public R<List<Coach>> getCoachList(){
        List<Coach> coachList= coachService.getList();
        return R.ok(coachList);
    }

    /**
     * 增加教练
     * @param coachDTO
     * @return
     */
    @PostMapping("add")
    public R<Void> addCoach(@RequestBody @Validated CoachDTO coachDTO){
        coachService.add(coachDTO);
        return R.ok();
    }

    /**
     * 删除教练
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    public R<Void> deleteCoach(@PathVariable Integer id){
        coachService.delete(id);
        return R.ok();
    }

    /**
     * 修改教练信息
     */
    @PutMapping("update/{id}")
    public R<Void> updateCoach(@RequestBody @Validated CoachDTO coachDTO,@PathVariable Integer id){
        coachService.update(coachDTO,id);
        return R.ok();
    }
    /**
     * 上传照片
     * @param image
     * @return
     */
    @PostMapping("uploadImage/{id}")
    public R<String> uploadImage(@PathVariable("id") Integer id, @RequestParam("image") MultipartFile image) {
        coachService.uploadImage(id,image);
        return R.ok("文件上传成功");
    }

    /**
     * 查询教练
     * @param id
     * @return
     */
    @GetMapping("search/{id}")
    public R<Coach> searchCoach(@PathVariable Integer id){
        Coach coach = coachService.search(id);
        return R.ok(coach);
    }

    /**
     * 发工资
     * @param id
     * @param wage
     * @return
     */
    @PostMapping("addWage/{id}")
    public R<Void> addWage(@PathVariable Integer id,@RequestParam Integer wage){
        coachService.addWage(id,wage);
        return R.ok();
    }

    /**
     * 获取教练工资
     * @param id
     * @return
     */
    @GetMapping("wage/{id}")
    public R<CoachWage> getWage(@PathVariable Integer id){
         CoachWage coachWage = coachService.getWage(id);
         return R.ok(coachWage);
    }

 }
